// detail小仓库
import { reqGetDetailInfo, reqGetAddToCart } from '@/api'
import { getUUID } from '@/utils/uuid_token'
const state = {
    detailInfo: {},
    uuid_token: getUUID()
}
const actions = {
    async getDetailInfo({ commit }, detailId) {
        let result = await reqGetDetailInfo(detailId)
        // console.log('@@@', result);
        if (result.code == 200) {
            commit('GETDETAILINFO', result.data)
        }

    },
    async addShopCart({ commit }, { skuId, skuNum }) {
        let result = await reqGetAddToCart(skuId, skuNum)
        // console.log('###', result);
        if (result.code == 200) {
            return "ok"
        } else {
            return Promise.reject(new Error('faile'))
        }
    }
}
const mutations = {
    GETDETAILINFO(state, detailInfo) {
        state.detailInfo = detailInfo
    }
}
const getters = {
    categoryView(state) {
        return state.detailInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.detailInfo.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.detailInfo.spuSaleAttrList || {}
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}